#include "button.hpp"
#include "content/data_provider.hpp"
#include "imgui.h"

void button::update_data (bindable_base *data)
{
    if (text_)
        text_->attach (data);
    if (callback_)
        callback_->attach (data);
}

void button::init_content (const xml_node &node)
{
    ui_control::init_content (node);
    text_     = create_data (node.attribute ("text").as_string (), std_string);
    callback_ = create_data (node.attribute ("callback").as_string (), callback);
}

void button::draw_self ()
{
    if (ImGui::Button (text_->get_std_string ().c_str ()) && callback_)
    {
        auto callback = callback_->get_callback ();
        callback.action (callback.user_data);
    }
}
